<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="zh-CN">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    #div1{
        width: 300px;
        height: 300px;
        background: red;
    }
</style>
<script>
    window.onload = function(){
        var btnObj = document.getElementById("btn");
        var div1Obj = document.getElementById("div1");
        btnObj.onclick = function(){
            //document.createElement创建元素
            var pObj = document.createElement("p");
            pObj.innerText = "我是创建的p标签";
            //把创建的p标签添加到div里
            //如果要删除的话，创建p标签对象，对象.remove();就是删除
            div1Obj.appendChild(pObj);
        }
    }
</script>
<body>
    <button id="btn">点击我在div里创建p标签</button>
    <div id="div1"></div>
</body>
</html>